package com.credithc.customers.manager.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.customers.base.ro.CancelFlowRo;
import com.credithc.customers.base.vo.CancelFlowVo;
import com.credithc.customers.manager.service.CancelFlowService;
import com.credithc.customers.manager.service.impl.AuthorizationServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 注销管理
 * @author: denghx
 * @date:   2020/11/30 14:19
 * @param:  null
 * @return:
 */
@RestController
@RequestMapping("/manager/yzt/v1")
public class CustomerCancelFlowController {
    @Autowired
    MessageFactory messageFactory;
    @Autowired
    CancelFlowService cancelFlowService;
    @Autowired
    AuthorizationServiceImpl authorizationService;

    @GetMapping("/cancelFlow")
    public Message getCancelFlow(@RequestHeader("token") String token, @PathParam("caller") String caller, HttpServletRequest request, @PathParam("requestNo") String requestNo, @PathParam("systemSign") String systemSign, @PathParam("subSystemSign") String subSystemSign, @PathParam("phone") String phone, @PathParam("preCustomerNo") String preCustomerNo,@PathParam("status") Integer status, @PathParam("createTimeStart") String createTimeStart, @PathParam("createTimeEnd") String createTimeEnd, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        CancelFlowRo ro = new CancelFlowRo();
        ro.setRequestNo(requestNo);
        ro.setSystemSign(systemSign);
        ro.setSubSystemSign(subSystemSign);
        ro.setPhone(phone);
        ro.setPreCustomerNo(preCustomerNo);
        ro.setStatus(status);
        ro.setCreateTimeStart(createTimeStart);
        ro.setCreateTimeEnd(createTimeEnd);
        ro.setPageNo(pageNo);
        ro.setPageSize(pageSize);
        if (StringUtils.isNotBlank(caller) && "TENANT".equals(caller)) {
            List<String> productCodes = authorizationService.authChannelRo(token,request);
            ro.setChannelNos(productCodes);
        }
        PageInfo<CancelFlowVo> list = cancelFlowService.getCancelFlow(ro);
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageInfo", list);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);

    }
}
